package com.ceshiren.chnjx.wework.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Set;

/**
 * @author: JJJJ
 * @date:2021/11/2 16:18
 * @Description: TODO
 */
public class GetCookiesUtil {
    static Logger logger = LoggerFactory.getLogger(GetCookiesUtil.class);
    public static void getCookies(WebDriver driver) throws Exception {

        driver.get("https://work.weixin.qq.com/wework_admin/frame");
        Thread.sleep(10000);
        // 获取当前页面的cookies
        Set<Cookie> cookies = driver.manage().getCookies();
        // 将cookies序列化陈yaml格式文件
        ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
        objectMapper.writeValue(new File("cookies.yaml"),cookies);
        logger.info("获取cookies，不执行测试");
        driver.close();
    }
}
